#!/bin/bash

# 定义变量方便修改
table_db=cy_database
hive=/home/software/hive-2.3.6/bin/hive

# 如果是输入的日期按照取输入日期；如果没输入日期取当前时间的前一天
if [ -n "$1" ] ;then
	do_date=$1
else
	do_date=`date -d "-1 day" +%F`
fi

sql="
with
tmp1_table as
(
select
	count(1) as num,
	null percent1,
	'企业库总数' content,
	'企业画像' name,
	cast(current_date() as string) as operate_time
from dws_enterprise_info

),


tmp2_table as
(
select
	count(1) as num,
	null percent1,
	'在库职位' content,
	'企业画像' name,
	cast(current_date() as string) as operate_time
from (
	select
		posts_name
	from dws_enterprise_position_require_detail
	group by posts_name
	)a
),


tmp3_table as
(
select
	sum(posts) as num,
	null percent1,
	'用工需求' content,
	'企业画像' name,
	cast(current_date() as string) as operate_time
from dws_enterprise_position_require_detail
),

tmp4_table as 公益性岗位 还在ods层表ods_probation_company 应给导入 dws_enterprise_position_require_detail
(
select
	sum(cast(recomm_welfare_job as int)) as num,
	null percent1,
	'公益性岗位' content,
	'企业画像' name,
	cast(current_date() as string) as operate_time
from ods_probation_company
)


insert overwrite table cy_database.ads_big_screen_result_ent_amount
select num,percent1,content,name,operate_time from tmp1_table

union all
select num,percent1,content,name,operate_time from tmp2_table

union all
select num,percent1,content,name,operate_time from tmp3_table

union all
select num,percent1,content,name,operate_time from tmp4_table

;
"

$hive -e "$sql"